<?php
class stat extends spController
{
	function __construct()
	{
	        // 必须加入启动父类构造函数的操作
	        parent::__construct();
	         
	        // 开始全局操作
	        $this->arr_cat = Product_Cat();
			$this->a = $_GET['a'];
			$this->c = $_GET['c'];
			
	}

	function index()
	{
		$m_youhui = spClass("youhui");
		$date = $_GET['date'] ? $_GET['date'] : date('Y-m-d', time());
		$count_user_sql = "SELECT count(distinct(`visitor_id`)) AS today_visit_result, DATE_FORMAT(`logintime`, '%Y-%m-%d') AS date FROM visit GROUP BY DATE_FORMAT(`logintime`, '%Y-%m-%d') ORDER BY DATE_FORMAT(`logintime`, '%Y-%m-%d') DESC";
		$tmp_array = $m_youhui->spCache(1800)->findSql($count_user_sql);
		foreach($tmp_array as $k=>$v) {
			$today_visit_result[$v['date']] = $v['today_visit_result'];
		}
		$this->today_visit_result = $today_visit_result;
		$count_click_sql = "SELECT count(`pid`) AS count_click_result, DATE_FORMAT(`clicktime`, '%Y-%m-%d') AS date FROM click GROUP BY DATE_FORMAT(`clicktime`, '%Y-%m-%d') ORDER BY DATE_FORMAT(`clicktime`, '%Y-%m-%d') DESC";
		$this->count_click_result = $m_youhui->spCache(1800)->findSql($count_click_sql);

		$this->display("admin/stat_index.html");
	}

	function history_pid()
	{
		$m_click = spClass('m_click');
		$pid = $_GET['pid'];
		$date_group_sql = "SELECT count(pid) AS nums, DATE_FORMAT(clicktime, '%Y-%m-%d') AS date FROM `click` WHERE `pid`='$pid' group by DATE_FORMAT(clicktime, '%Y-%m-%d') ORDER BY DATE_FORMAT(clicktime, '%Y-%m-%d') DESC";
		$this->result = $m_click->findSql($date_group_sql);
		//var_dump($result);
		$this->display("admin/history_pid.html");
	}

	function click_by_date()
	{
		$m_click = spClass('m_click');
		$this->tdate = $date = $_GET['date'] ? $_GET['date'] : date('Y-m-d', time());
		$click_group_sql = "SELECT count(a.`pid`) AS nums, a.pid, b.title FROM `click` a LEFT JOIN `youhui` b ON a.pid=b.pid WHERE DATE_FORMAT(a.`clicktime`, '%Y-%m-%d')='$date' GROUP BY a.`pid` ORDER BY count(a.`pid`) DESC";
		$this->result = $m_click->findSql($click_group_sql);
		$this->display("admin/day_history_pid.html");
	}

/*
	function ()
	{
	}
*/
}
?>